package leetcode.code2007;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int[] findOriginalArray(int[] changed) {
		int len = changed.length;
		if ((len & 1) == 1) {
			return new int[] {};
		}
		int[] ans = new int[len >> 1];
		int l = 0, r = 0;
		Arrays.sort(changed);
		Arrays.fill(ans, -1);
		int i = 0;
		while (i < len) {
			int num = changed[i];
			if (num == ans[l] * 2) {
				l++;
			} else {
				if (r < (len >> 1)) {
					ans[r++] = num;
				} else {
					return new int[] {};
				}
			}
			i++;
		}
		if (l == r && i == len) {
			return ans;
		}
		return new int[] {};
	}

	@Override
	public void debug4() {
		this.findOriginalArray(H.str2array3("[1,3,4,2,6,8]"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
